s = imfinfo('cameraman.tif'); %read image information in structured variable s
B = imread('cameraman.tif');  %read Greyscale image
figure,imshow(B),title('Original Greyscale Image');
C = [512,512,3];  %declare the colour image matrix
for  i = 1: s.Height
   for j = 1: s.Width 
    if(B(i,j) < 50)     %assign one colour to pixels having intensity less than 50
       C(i,j,1) = 256;  %assign red colour
        C(i,j,2) = 0;
         C(i,j,3) = 0;
   else if (B(i,j) > 50) && (B(i,j) < 100)%assign one colour to pixels having intensity between 50 and 100
        C(i,j,1) = 0;  %assign cyan colour
        C(i,j,2) = 256;
         C(i,j,3) = 256;
       else if (B(i,j) > 100) && (B(i,j) < 150)%assign one colour to pixels having intensity between 100 and 150
          C(i,j,1) = 256;%assign magenta colour
        C(i,j,2) = 0;
         C(i,j,3) = 256;
           else if (B(i,j) > 150) && (B(i,j) < 200)%assign one colour to pixels having intensity between 150 and 200
          C(i,j,1) = 256;%assign yellow colour
          C(i,j,2) = 256;
         C(i,j,3) = 0;
               end
           end
       end
     end
   end
end
figure,imshow(uint8(C)),title('Colour Image');%convert all values to unsigned int8 format and display image
